﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace FichoWeb.Models
{
    public class FichoContext: DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<Image> Images { get; set; }
        public DbSet<Album> Albums { get; set; }
        public DbSet<Blog> Blogs { get; set; }

        public FichoContext()
        {
            Configuration.ProxyCreationEnabled = false;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer(new FichoContextInitializer());

            base.OnModelCreating(modelBuilder);
        }

        public class FichoContextInitializer: DropCreateDatabaseAlways<FichoContext>
        {
            protected override void Seed(FichoContext context)
            {
                base.Seed(context);
                context.Users.Add(new User()
                {
                   Username = "admin",
                   Password = "admin",
                   Role = "administrator",
                   Active = true
                });

                context.SaveChanges();
            }
        }
    }
}